package com.zlm.linked;

/**
 * @author zlm
 * @date 2025/4/30
 * 反转链表
 */
public class ReverseLinkedNode {

    public static void main(String[] args) {
        Node<Integer> head = new Node<>(1);
        head.addNode(2);
        head.addNode(3);
        head.addNode(4);
        head.addNode(5);
        head.addNode(6);
        Node<Integer> reverseNode = reverseNode(head);
        reverseNode.printNode();
    }

    public static Node<Integer> reverseNode(Node<Integer> head) {
        //前序节点
        Node<Integer> pre = null;
        //下一个节点
        Node<Integer> nxt = head;
        //当前节点
        Node<Integer> cur = head;

        while (cur != null){
            nxt = cur.next;
            cur.next = pre;
            pre = cur;
            cur = nxt;
        }
        return pre;
    }

    /**
     * 反转指定区间的链表
     * @param head
     * @return
     */
    public static Node<Integer> reverseIntervalNode(Node<Integer> head,  int start, int end) {
        if (head == null || head.next == null || start == end){
            return head;
        }
        Node<Integer> cur = head;
        while (cur != null){

        }

        return null;

    }
}
